package role

import (
	"context"
	"github.com/gogf/gf/v2/frame/g"
	"github.com/gogf/gf/v2/util/gconv"
	"xr-game-server/core/constants/common"
	"xr-game-server/core/httpserver"
	"xr-game-server/dao/roledao"
	"xr-game-server/dto/roledto"
)

func GetAllRole(ctx context.Context, req *roledto.RoleReq) (res *roledto.RoleRes, err error) {
	accountId := g.RequestFromCtx(ctx).GetHeader(httpserver.AuthId)
	caches := roledao.GetRoleBy(gconv.Uint64(accountId))
	data := make([]*roledto.RoleDto, common.Zero)
	for _, role := range caches {
		data = append(data, roledto.NewRoleDto(role))
	}
	return &roledto.RoleRes{
		Data: data,
	}, nil
}

func PageRole(req *roledto.PageRoleReq) (*httpserver.CMSQueryResp, error) {
	return httpserver.NewCMSQueryResp(roledao.PageRole(req)), nil
}
